package com.eostoken.eos_wallet.ui.fragment;

import android.content.Intent;
import android.view.View;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.FragmentUtils;
import com.eostoken.eos_wallet.R;
import com.eostoken.eos_wallet.base.BaseFragment;
import com.eostoken.eos_wallet.ui.activity.LanguageActivity;
import com.eostoken.eos_wallet.ui.fragmentfactory.FragmentFactory;
import com.fredy.mvp.BasePresenter;
import com.fredy.mvp.BaseView;
import com.fredy.mvp.Model;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

import butterknife.BindView;
import butterknife.OnClick;

import static com.eostoken.eos_wallet.utils.Constants.ADD_WALLET;
import static com.eostoken.eos_wallet.utils.Constants.CREATE_WALLET;
import static com.eostoken.eos_wallet.utils.Constants.IMPORT_WALLET;

public class AddWalletFragment extends BaseFragment {
    @BindView(R.id.logoIv)
    AppCompatImageView logoIv;
    @BindView(R.id.creareWalletBtn)
    QMUIRoundButton creareWalletBtn;
    @BindView(R.id.importAccountTv)
    AppCompatTextView importAccountTv;
    @BindView(R.id.clauseTv)
    AppCompatTextView clauseTv;
    @BindView(R.id.text1)
    AppCompatTextView text1;
    @BindView(R.id.text2)
    AppCompatTextView text2;
    @BindView(R.id.topbar)
    QMUITopBarLayout topbar;
    @BindView(R.id.languageSettingsTv)
    AppCompatTextView languageSettingsTv;
    private boolean isMain = true;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_add_wallet;
    }

    @Override
    protected void initData() {
        isMain = getArguments().getBoolean("isMain", true);
    }

    @Override
    protected void initView(View contentView) {
        logoIv.setImageDrawable(ContextCompat.getDrawable(getActivity(), isMain ? R.mipmap.big_logo : R.mipmap.eostoken_logo));
        text1.setVisibility(isMain ? View.GONE : View.VISIBLE);
        text2.setVisibility(isMain ? View.GONE : View.VISIBLE);
        clauseTv.setVisibility(isMain ? View.VISIBLE : View.GONE);
        topbar.setBackgroundColor(ColorUtils.getColor(isMain ? R.color.app_color_common_white : R.color.app_color_blue));
        topbar.setTitle(isMain ? "" : getString(R.string.str_add_wallet));
        if (isMain) {
            topbar.setVisibility(View.GONE);
            languageSettingsTv.setVisibility(View.VISIBLE);
        } else {
            topbar.setVisibility(View.VISIBLE);
            languageSettingsTv.setVisibility(View.GONE);
            topbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (isMain) {
            QMUIStatusBarHelper.setStatusBarLightMode(getActivity());
        } else {
            QMUIStatusBarHelper.setStatusBarDarkMode(getActivity());
        }
        BarUtils.setStatusBarColor(getActivity(), ColorUtils.getColor(isMain ? R.color.app_color_common_white : R.color.app_color_blue));
    }

    @Override
    public Model createModel() {
        return null;
    }

    @Override
    public BaseView createView() {
        return null;
    }

    @Override
    public BasePresenter createPresenter() {
        return null;
    }

    @Override
    public void finishRefresh() {

    }

    @OnClick({R.id.languageSettingsTv, R.id.creareWalletBtn, R.id.importAccountTv, R.id.clauseTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.languageSettingsTv:
                Intent intent = new Intent(getActivity(), LanguageActivity.class);
                ActivityUtils.startActivity(intent);
                finish();
                break;
            case R.id.creareWalletBtn:
                FragmentUtils.replace(getFragmentManager(), FragmentFactory.getInstatic().getFragment(CREATE_WALLET), R.id.frag_container, "CreateAccountFragment", true);
                break;
            case R.id.importAccountTv:
                FragmentUtils.replace(getFragmentManager(), FragmentFactory.getInstatic().getFragment(IMPORT_WALLET), R.id.frag_container, "ImportWalletFragment", true);
                break;
            case R.id.clauseTv:
                break;
        }
    }

//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//        setRetainInstance(true);
//        super.onCreate(savedInstanceState);
//    }
}
